package com.example.nyf.mapper;

import com.example.nyf.dto.SysUserTDO;
import com.example.nyf.entity.SysUser;
import com.example.nyf.mapper.provider.SysUserProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


public interface SysUserMapper {

    @Insert("insert into sys_user(dept_id, user_name, password, phone, avatar, salt, status, remark, add_user_id, add_user_name, add_time" +
            ") values(#{user.dept_id}, #{user.user_name}, #{user.password}, #{user.phone}, #{user.avatar}, #{user.salt}, #{user.status}" +
            ", #{user.remark}, #{user.add_user_id}, #{user.add_user_name}, #{user.add_time})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public int user_add(@Param("user") SysUser sysUser);

    /**
     * 返回用户信息根据id
     * @param id
     * @return
     */
    @Select("select a.*,b.role_id from sys_user a left outer join sys_user_role b on a.id=b.user_id where a.id = #{id}")
    public SysUserTDO getSysUserById(@Param("id") String id);

    /**
     * 返回用户信息根据名称
     * @param name
     * @return
     */
    @Select("select * from sys_user where user_name = #{user_name}")
    public SysUser getSysUserByName(@Param("user_name") String user_name);


    /**
     * 返回用户信息 分页
     * @param mp
     * @return
     */
    @SelectProvider(type = SysUserProvider.class, method = "getSysUserList")
    public List<SysUser> getSysUserList(Map mp);

    @Delete("delete from sys_user where id = #{id}")
    public int deleteSysUser(Integer id);

    @Update("update sys_user set login_time = #{login_time}, login_num = login_num+1, login_ip = #{login_ip} where " +
            " id = #{id}")
    public int updateSysUserLoginInfo(SysUser sysUser);

    @UpdateProvider(type = SysUserProvider.class, method = "updateSysUser")
    public int updateSysUser(SysUserTDO sysUserTDO);
}
